
//
//  SelectAddressViewController.m
//  MJApp
//
//  Created by 王亮 on 15/7/28.
//  Copyright (c) 2015年 wangliang. All rights reserved.
//

#import "SelectAddressViewController.h"
#import "MineAddressTableViewCell.h"

@interface SelectAddressViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong)UITableView *tableView;
@property (retain,nonatomic) NSArray *addressList;

@end

@implementation SelectAddressViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self obationData];
    [self UI];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)UI {
    
    self.title = @"选择地址";
    UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    tableView.backgroundColor = Color_Back_Black;
    tableView.delegate = self;
    tableView.dataSource = self;
    [self.view addSubview:tableView];
    self.tableView = tableView;
    tableView.separatorColor = [UIColor clearColor];
}

- (void)obationData {
    
    NSDictionary *dic = @{@"user_id":[userInfoTool share].ID};
    [WLHttpRequestAfter userGetUserAddressWithParam:dic usingSucessBlock:^(BOOL isSucess, NSDictionary *resultDictionary) {
        
        if (resultDictionary) {
            
            self.addressList = resultDictionary[@"data"];
        }
        [self.tableView reloadData];
        
    } andFailureBlock:^(NSError *resultError) {
        
    }];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.addressList.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    MineAddressTableViewCell *cell = (MineAddressTableViewCell *)[self tableView:tableView cellForRowAtIndexPath:indexPath];
    return cell.cellHigh;
 
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    

    MineAddressTableViewCell *cell = [MineAddressTableViewCell initWithTableView:tableView];
    cell.infoDic = self.addressList[indexPath.row];
    cell.defaultImageView.hidden = YES;
    return cell;

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSDictionary *dic = self.addressList[indexPath.row];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"selectAddress" object:nil userInfo:dic];
    [self.navigationController popViewControllerAnimated:YES];
}

@end
